package com.leyou.cart.listener;

import com.leyou.common.constants.LyConstants;
import com.leyou.common.constants.MQConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class OrderDownListener {
    
    @Autowired
    private StringRedisTemplate redisTemplate;
    
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MQConstants.Queue.CART_DELETE_QUEUE,durable = "true"),
            exchange = @Exchange(value = MQConstants.Exchange.ITEM_EXCHANGE_NAME,type = ExchangeTypes.TOPIC),
            key = MQConstants.RoutingKey.CART_DELETE_KEY))
    public void deleteCarts(Long userId){
        redisTemplate.delete(LyConstants.CART_PRE+userId);
    }
}
